/*
 * Copyright (C) 2010 Ryan Morton
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.games.rm.patternpuzzler;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;

import android.app.Activity;
import android.os.Bundle;
import android.view.animation.AnimationUtils;
import android.widget.LinearLayout;
import android.widget.TextView;

public class HighScoresActivity extends Activity
{
	private LinearLayout mainLayout;
	private TextView highScore01Date;
	private TextView highScore01GameType;
	private TextView highScore01Level;
	private TextView highScore02Date;
	private TextView highScore02GameType;
	private TextView highScore02Level;
	private TextView highScore03Date;
	private TextView highScore03GameType;
	private TextView highScore03Level;
	private TextView highScore04Date;
	private TextView highScore04GameType;
	private TextView highScore04Level;
	private TextView highScore05Date;
	private TextView highScore05GameType;
	private TextView highScore05Level;
	private ArrayList<TextView[]> highScoreTextBoxes;
	
	private ArrayList<HighScore> myHighScores;
	
	@Override
	protected void onCreate(Bundle savedInstanceState)
	{
		super.onCreate(savedInstanceState);
		//set up the window properties
        Utilities.setupActivityWindow(this);
        
        //inflate the main layout
        this.setContentView(R.layout.high_scores);
        
        //run the init();
        this.init();
        
        this.loadHighScores();
        
        mainLayout.startAnimation(AnimationUtils.loadAnimation(this, R.anim.slide_in_main_menu));
	}
	
	private void init()
	{
		mainLayout = (LinearLayout)this.findViewById(R.id.High_Scores_Layout);
		highScore01Date = (TextView) this.findViewById(R.id.High_Scores_01_Date);
		highScore01GameType = (TextView) this.findViewById(R.id.High_Scores_01_GameType);
		highScore01Level = (TextView) this.findViewById(R.id.High_Scores_01_Level);
		highScore02Date = (TextView) this.findViewById(R.id.High_Scores_02_Date);
		highScore02GameType = (TextView) this.findViewById(R.id.High_Scores_02_GameType);
		highScore02Level = (TextView) this.findViewById(R.id.High_Scores_02_Level);
		highScore03Date = (TextView) this.findViewById(R.id.High_Scores_03_Date);
		highScore03GameType = (TextView) this.findViewById(R.id.High_Scores_03_GameType);
		highScore03Level = (TextView) this.findViewById(R.id.High_Scores_03_Level);
		highScore04Date = (TextView) this.findViewById(R.id.High_Scores_04_Date);
		highScore04GameType = (TextView) this.findViewById(R.id.High_Scores_04_GameType);
		highScore04Level = (TextView) this.findViewById(R.id.High_Scores_04_Level);
		highScore05Date = (TextView) this.findViewById(R.id.High_Scores_05_Date);
		highScore05GameType = (TextView) this.findViewById(R.id.High_Scores_05_GameType);
		highScore05Level = (TextView) this.findViewById(R.id.High_Scores_05_Level);
		
		highScoreTextBoxes = new ArrayList<TextView[]>(5);
		highScoreTextBoxes.add(new TextView[]{highScore01Date,highScore01GameType,highScore01Level});
		highScoreTextBoxes.add(new TextView[]{highScore02Date,highScore02GameType,highScore02Level});
		highScoreTextBoxes.add(new TextView[]{highScore03Date,highScore03GameType,highScore03Level});
		highScoreTextBoxes.add(new TextView[]{highScore04Date,highScore04GameType,highScore04Level});
		highScoreTextBoxes.add(new TextView[]{highScore05Date,highScore05GameType,highScore05Level});
	}
	
	private void loadHighScores()
	{
		myHighScores = Utilities.loadHighScores(this);
		if(myHighScores.size()!=0)
		{
			TextView[] currentTextViewArray;
			int j=0;
			for(int i = 0;i<myHighScores.size();i++)
			{
				currentTextViewArray = highScoreTextBoxes.get(j);
				currentTextViewArray[0].setText(myHighScores.get(i).getDate());
				if(myHighScores.get(i).getGameType() == Utilities.GAME_TYPE_4_BUTTON)
				{
					currentTextViewArray[1].setText("4-Button");
				}
				else
				{
					currentTextViewArray[1].setText("5-Button");
				}
				currentTextViewArray[2].setText(""+myHighScores.get(i).getLevel());
				j++;
			}
		}
	}
}
